package crossover;

import executor.ReflectionExecutor;
import ga.GAInfo;
import ga.Individual;

import java.io.File;
import java.util.Calendar;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;


import model.TestClusterBuilder;
import operations.Operation;
import util.GAConfig;
import util.GAOperationsConfig;
import util.Log;
import util.Randomness;

public class TestCrossOvermain {
	public static void main(String[] args) {
		String logFilePath = "c:/MAMDA/MAMDA2014/temp/CrossOver.txt";
		Log.logConfig(logFilePath);
		new File(logFilePath).getAbsolutePath();
		
		
	       GAInfo     gaInfo     = new GAInfo();
			long startTime = Calendar.getInstance().getTimeInMillis();
			gaInfo.setTestTimeOut(60 * 500);
			 gaInfo.setTestTimeOut( 60 * 1000*10); ;
				gaInfo.setStartTime(startTime);

	Crossover crossoverStrategy = GAOperationsConfig.getCrossoverStrategy();

		Randomness.reset(20);
		
		 Set<Class<?>> allClasses = new LinkedHashSet<Class<?>>();
	      //get class from file
	      allClasses.addAll(TestClusterBuilder.readClassFromFile());

	      
	      TestClusterBuilder TestCluster = new TestClusterBuilder(allClasses);
	      
		  List<Operation> initialConstructors= Operation.generateInitialConstructors(TestCluster);
	      List<Operation> ops=new LinkedList<Operation>();
    	  ops.addAll(Operation.randomlyGenerate(TestCluster,10));
	      Individual individual1=new Individual(initialConstructors,ops);
	      
	//      ReflectionExecutor.execute(gaInfo,individual1);
	      initialConstructors= Operation.generateInitialConstructors(TestCluster);
	    	 ops=new LinkedList<Operation>();
	    	  ops.addAll(Operation.randomlyGenerate(TestCluster,10));
	    	  
		      Individual individual2=new Individual(initialConstructors,ops);
				System.out.println("Crossover Strategy: "
						+ crossoverStrategy.getClass().getName());
				
//				ReflectionExecutor.execute(gaInfo,individual2);
				Individual[] offspring = crossoverStrategy.crossOver(individual1, individual2);
	
				System.out.println("1)\n" + individual1.toString());
				System.out.println("2)\n" + individual2.toString());

				System.out.println("offspring1:" + offspring[0].toString());
				System.out.println("\noffspring2:" + offspring[1].toString());
				
				
//				ReflectionExecutor.execute(gaInfo,offspring[0]);
//				ReflectionExecutor.execute(gaInfo,offspring[1]);
				System.exit(0);

	}

}
